package com.wuseguang.springcloud.service.impl;

import com.wuseguang.springcloud.dao.jdbc.ClassesJdbc;
import com.wuseguang.springcloud.dao.mapper.ClassesMapper;
import com.wuseguang.springcloud.dao.repository.ClassesRepository;
import com.wuseguang.springcloud.service.ClassesService;
import com.wuseguang.springcloud.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 班级信息 服务实现类
 * </p>
 *
 * @author
 * @since 2020-02-10
 */
@Service
public class ClassesServiceImpl implements ClassesService {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private ClassesMapper classesMapper;
    @Autowired
    private ClassesJdbc classesJdbc;
    @Autowired
    private ClassesRepository classesRepository;

    @Override
    public Result findNoClass(Integer gradeId) {

        logger.info("查询没有数据权限的班级");

        String sql = "select id,name from classes where grade_id =? and graduation =0";
        //查询班级信息
        List<Map<String, Object>> list = classesJdbc.queryListMap(sql, gradeId);

        return new Result(list);
    }

    @Override
    public Result findNoGrade(String schoolId) {

        logger.info("查询没有数据权限的年级");

        String sql = "select id,name from grade where school_id = ? ORDER BY other,education_id,id";

        //查询年级信息
        List<Map<String, Object>> list = classesJdbc.queryListMap(sql, schoolId);

        return new Result(list);
    }

    @Override
    public Result findClasses(String schoolId, String teacherId, Integer gradeId) {
        //查询教师的数据权限
        int type = classesJdbc.findDatePermissions(teacherId);
        //查询教师的班级
        List<Map<String, Object>> list = classesJdbc.queryClassList(String.valueOf(gradeId), type, schoolId, teacherId);
        return new Result(list);
    }

    @Override
    public Result findGrade(String schoolId, String teacherId) {
        //查询教师的数据权限
        int type = classesJdbc.findDatePermissions(teacherId);
        //查询教师的年级
        List<Map<String, Object>> list = classesJdbc.queruGradeList(teacherId, type, schoolId);
        return new Result(list);
    }
}
